package ui2;

import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Dimension;
import javax.swing.ImageIcon;


public class Menu {

        private JFrame frmGui;
        private JPanel panel;
        private JMenuBar menuBar;
        
        /**
         * Launch the application.
         */
        public static void main(String[] args) {
                EventQueue.invokeLater(new Runnable() {
                        public void run() {
                                try {
                                        Menu window = new Menu();
                                        window.frmGui.setVisible(true);
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }
                        }
                });
        }

        /**
         * Create the application.
         */
        public Menu() {
                initialize();
        }

        /**
         * Initialize the contents of the frame.
         */
        private void initialize() {
                frmGui = new JFrame();
                frmGui.setTitle("GUI Example");
                frmGui.setBounds(100, 100, 900, 550);
                frmGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frmGui.getContentPane().setLayout(new BorderLayout(0, 0));
                
                panel = new JPanel();
                frmGui.getContentPane().add(panel, BorderLayout.CENTER);
                
                //JToolBar toolBar = new JToolBar();
                //frmGui.getContentPane().add(toolBar, BorderLayout.SOUTH);
                
                //JToggleButton tglbtn = new JToggleButton("Node is now running...");
                //toolBar.add(tglbtn);
                
                menuBar = new JMenuBar();
                menuBar.setMargin(new Insets(0, 20, 0, 20));
                menuBar.setFont(new Font("Segoe UI", Font.PLAIN, 14));
                frmGui.setJMenuBar(menuBar);
                
                JMenu mnNewMenu = new JMenu("Send ");
                mnNewMenu.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 14));
                mnNewMenu.setSize(new Dimension(20, 0));
                menuBar.add(mnNewMenu);
                
                JMenuItem mntmNewMenuItem_5 = new JMenuItem("Task");
                mntmNewMenuItem_5.setIcon(new ImageIcon(Menu.class.getResource("/resources/sendtask.png")));
                /*mntmNewMenuItem_5.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseReleased(MouseEvent arg0) {
                                setPanel("panelTask");
                        }
                });*/
                mnNewMenu.add(mntmNewMenuItem_5);
                
                JMenuItem mntmNewMenuItem_3 = new JMenuItem("Event");
                mntmNewMenuItem_3.setIcon(new ImageIcon(Menu.class.getResource("/resources/sendevent.png")));
                /*mntmNewMenuItem_3.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseReleased(MouseEvent arg0) {
                                setPanel("panelParameter");
                        }
                });*/
                mnNewMenu.add(mntmNewMenuItem_3);
                
                JMenu mnNewMenu_1 = new JMenu(" Queue ");
                mnNewMenu_1.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 14));
                menuBar.add(mnNewMenu_1);
                
                JMenuItem mntmNewMenuItem_4 = new JMenuItem("View your queue");
                mntmNewMenuItem_4.setIcon(new ImageIcon(Menu.class.getResource("/resources/viewyourqueue.png")));
                /*mntmNewMenuItem_4.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseReleased(MouseEvent arg0) {
                               setPanel("panelYourQueue");
                       }
                });*/
                mnNewMenu_1.add(mntmNewMenuItem_4);
                
                JMenuItem mntmViewYourSent = new JMenuItem("View your sent request");
                mntmViewYourSent.setIcon(new ImageIcon(Menu.class.getResource("/resources/viewsent.png")));
                /*mntmViewYourSent.addMouseListener(new MouseAdapter() {
                	@Override
                	public void mouseReleased(MouseEvent e) {
                		setPanel("panelSent");
                	}
                });*/
                mnNewMenu_1.add(mntmViewYourSent);
                
                JMenu mnNewMenu_2 = new JMenu(" Configuration ");
                mnNewMenu_2.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 14));
                menuBar.add(mnNewMenu_2);
                
                JMenuItem mntmNewMenuItem = new JMenuItem("PC");
                mntmNewMenuItem.setIcon(new ImageIcon(Menu.class.getResource("/resources/configpc.png")));
                /*mntmNewMenuItem.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseReleased(MouseEvent arg0) {
                                setPanel("panelPc");
                        }
                });*/
                mnNewMenu_2.add(mntmNewMenuItem);
                
                JMenuItem mntmNewMenuItem_1 = new JMenuItem("Port / IP");
                mntmNewMenuItem_1.setIcon(new ImageIcon(Menu.class.getResource("/resources/configport.png")));
                /*mntmNewMenuItem_1.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseReleased(MouseEvent arg0) {
                                setPanel("panelPort");
                        }
                });*/
                mnNewMenu_2.add(mntmNewMenuItem_1);
                
                JMenuItem mntmNewMenuItem_2 = new JMenuItem("Queue");
                mntmNewMenuItem_2.setIcon(new ImageIcon(Menu.class.getResource("/resources/configqueue.png")));
                /*mntmNewMenuItem_2.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseReleased(MouseEvent arg0) {
                                setPanel("panelQueue");
                        }
                });*/
                mnNewMenu_2.add(mntmNewMenuItem_2);
                
                JMenuItem mntmNewMenuItem_8 = new JMenuItem("Discovery");
                mntmNewMenuItem_8.setIcon(new ImageIcon(Menu.class.getResource("/resources/configDiscovery.png")));
                /*mntmNewMenuItem_8.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseReleased(MouseEvent arg0) {
                            setPanel("panelDiscovery");
                    }
                });*/
                mnNewMenu_2.add(mntmNewMenuItem_8);
                
                JMenu mnNewMenu_3 = new JMenu(" Help ");
                mnNewMenu_3.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 14));
                menuBar.add(mnNewMenu_3);
                
                JMenuItem mntmNewMenuItem_6 = new JMenuItem("Guide");
                mntmNewMenuItem_6.setIcon(new ImageIcon(Menu.class.getResource("/resources/help.png")));
                mnNewMenu_3.add(mntmNewMenuItem_6);
                
                JMenuItem mntmNewMenuItem_7 = new JMenuItem("About");
                mntmNewMenuItem_7.setIcon(new ImageIcon(Menu.class.getResource("/resources/about.png")));
                mnNewMenu_3.add(mntmNewMenuItem_7);
        }
        
        /**
         * Method that takes in input a String and loads the relative panel
         * @param s String with the name of the panel to load
         * @see Panel
         */
        public void setPanel(String s){
                Panel p = new Panel();		//create Panel object
                panel.removeAll();			//clean original jpanel
                JPanel tmp = new JPanel();	//tmp container
                tmp=p.getPanel(s);			//method that return Panel
                if(tmp!=null)
                {
                	panel.add(tmp);				//add Pannel
                	panel.repaint();			//refresh
                	panel.validate();			//finalize original jpanel
                	panel.setVisible(true);		//visible
                }
        }
        
        public JFrame getFrame()
        {
        	return this.frmGui;
        }
        
        public JMenuBar getMenuBar()
        {
        	return this.menuBar;
        }
        
        public JPanel getMainPanel()
        {
        	return this.panel;
        }
        
        public void setMainPanel(JPanel newPanel)
        {
        	this.panel.removeAll();
    		this.panel.add(newPanel);				//add Pannel
        	this.panel.repaint();			//refresh
        	this.panel.validate();			//finalize original jpanel
        	this.panel.setVisible(true);
        }
}
       